<?php
/**
 * Created by JetBrains PhpStorm.
 * User: avnovoselov
 * Date: 21.10.12
 * Time: 12:52
 * To change this template use File | Settings | File Templates.
 */
class router
{
    public static   $rights = array();
    private static  $mvc         = array(
        'controller'    => 'main',
        'action'        => 'index',
        'id'            => 0
    );
    private static $params      = '';
    private static $types       = array(
        1   => 'static',
        2   => 'redirect',
        3   => 'other_mvc'
    );

    public static function init()
    {
        self::$mvc = url::$mvc;
        $buf = '/'.url::$mvc['controller'].'/'.url::$mvc['action'].'/';
        $buf = '/main/index/' ? '/' : $buf;

        if (isset(self::$rights[$buf]))
        {
            switch (self::$rights[$buf]['type'])
            {
                case 1:
                {
                    self::$mvc  = array(
                        'controller'    => 'load',
                        'action'        => 'static',
                        'id'            => !empty(self::$rights[$buf]['id']) ? self::$rights[$buf]['id'] : 0
                    );
                    self::$params       = self::$rights[$buf]['path'];
                    break;
                }
                case 2:
                {
                    header('HTTP/1.1 301 Moved Permanently');
                    header('location: '. self::$rights[$buf]['path']);
                    break;
                }
                case 3:
                {
                    self::$mvc = array_merge(self::$mvc, self::$rights[$buf]);
                    break;
                }
            }
        }
        url::$mvc = self::$mvc;
    }
}
